﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using Presentation.Shell.Interfaces;
using Microsoft.Practices.Unity;
using Infrastructure.CrossCutting.Security;

namespace VPL.Shell
{
    /// <summary>
    /// Interaction logic for Logon.xaml
    /// </summary>
    public partial class Logon : Window, ILogon
    {
        private readonly IUnityContainer _container;
        private readonly ILogonService _logonService;


        public Logon(IUnityContainer container, ILogonService logonService)
        {
            InitializeComponent();

            this._container = container;

            this._logonService = logonService;

            this.DataContext = logonService;

            this._logonService.UserAuthenticated += this.OnUserAuthenticated;

            this._logonService.LogonTry += this.OnLogonTry;                

            LogonResult = false;


        }

        public bool LogonResult { get; set; }

        public void OnUserAuthenticated()
        {
                LogonResult = true;
                this.Close();
            
            
        }

        private void OnLogonTry()
        {
            _logonService.Password = textBox2.Password;
        }


        private void Cancel(object sender, RoutedEventArgs e)
        {
            this.Close();
            Environment.Exit(0);
        }
    }
}
